package com.sys.service.impl;

import com.sys.bean.Parklot;
import com.sys.bean.RespBean;
import com.sys.mapper.ParklotMapper;
import com.sys.service.ParklotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ParklotServiceImpl implements ParklotService {
    @Autowired
    private ParklotMapper parklotMapper;
    @Override
    public boolean insert(Parklot parklot) {
        if (parklotMapper.selectByParkName(parklot.getParkName()) != null){
            RespBean.error("该停车场的信息已存在，请勿重复添加");
        }
        return parklotMapper.insert(parklot) == 1;
    }

    @Override
    public boolean delete(Integer parkId) {
        if (parklotMapper.selectByParkId(parkId) != null){
            RespBean.error("该停车场已存在，无法删除");
        }
        return parklotMapper.delete(parkId) == 1;
    }

    @Override
    public boolean update(Parklot parklot) {
        if (parklotMapper.update(parklot)){
            RespBean.ok("修改停车场信息成功");
        }
        return parklotMapper.update(parklot);
    }

    @Override
    public Parklot selectById(Integer parkId) {
        if (parklotMapper.selectByParkId(parkId) == null){
            RespBean.error("该停车场不存在");
        }
        return parklotMapper.selectByParkId(parkId);
    }

    @Override
    public List<Parklot> selectAll() {
        return parklotMapper.selectAll();
    }

    @Override
    public Parklot selectByParkName(String parkName) {
        if (parklotMapper.selectByParkName(parkName)==null){
            RespBean.error("不存在该停车场");
        }
        return parklotMapper.selectByParkName(parkName);
    }
}
